function [pcm,indm]=scomb(nlag,svec);
% function [pcm,indm]=scomb(nlag,svec);
% Possible combinations of the vector svec with nlags 
% length of svec taken as number of possible states
% Inputs
% -------
% svec must be a row vector ( [1 ns] for states ) 
% nlag number of lags allowed 
% Output 
% ------
% pcm Possible States Combination Matrix 
% indm  Indicator matrix of positions where each element in svec 
%       appears 
% Columns correspond to the values ordered as standard in time series  
% s(t)  s(t-1)   s(t-nlag-1)    s(t-nlag) 
% AJ 12/4/03
[nr,nc]=size(svec); 
if nr > 1; 
    svec = svec'; 
    ns=nr; 
else 
    ns=nc; 
end 
ind=(ns.^(0:nlag+1))'; 
pcm=zeros(ind(end),nlag);
ok=ind(1:end-1);
ik=flipud(ok); 
for ii=1:nlag+1;
    ti=kron(svec, ones(1,ik(ii)) ); 
    to=kron(ti, ones(ok(ii),1) )';
    pcm(:,ii)=to(:); 
end
pcm=fliplr(pcm); 
indm=sind(pcm,svec); 